﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

namespace TheardLearnWeb.Learn
{
    public partial class ThreadLearn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        public void Bind()
        {
            this.divContent.InnerHtml = "Main thread:starting a dedicated thread to do an asynchronous operation </br>";
            Thread dedicatedThread = new Thread(ComputerBoundOp);
            dedicatedThread.Start(10);

            this.divContent.InnerHtml += "Main there :Doing other work there... </br>";
            //Thread.Sleep(1000);

            dedicatedThread.Join();
            this.divContent.InnerHtml += "Hit <Enter> to end this program... </br>";
        }

        private void ComputerBoundOp(object obj)
        {
            Thread.Sleep(1000);
            this.divContent.InnerHtml += string.Format("In ComputerBoundOp:state={0} </br>", obj);
            
        }

        public void Data()
        {
                
        }

    }
}